public class num1137 {
    public int tribonacci(int n) {
        if(n == 0) {
            return 0;
        }
        if(n == 1 || n == 2) {
            return 1;
        }
        int ans = 0;
        int prev = 0;
        int next = 1;
        int cur = 1;
        for (int i = 3;i <= n;i ++) {
            ans = prev + next + cur;
            prev = next;
            next = cur;
            cur = ans;
        }
        return ans;
    }
}
